﻿using Bikiball.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bikiball.Game
{
    public enum MapCase
    {
        Empty = 0,
        Default = 1,
        Wall,
        Blue,
        Star,
        Note,
        Left,
        Right,
        Up,
        Down,
        Jump,
        Glass,
        Lava,
        Grass,
        Water,
        Block,
        Grill,
        
    }

    public class Map : GameObject
    {
        public int SizeX { get; private set; }
        public int SizeY { get; private set; }
        public int SizeZ { get; private set; }
        public MapCase[, ,] MapCases { get; private set; }
        public Map(int x, int y, int z)
        {
            this.SizeX = x;
            this.SizeY = y;
            this.SizeZ = z;
            Init(x, y, z);
            //Test();
        }

        public void Test()
        {
            this.SizeX = 2;
            this.SizeY = 2;
            this.SizeZ = 2;
            this.MapCases = new MapCase[2, 2, 2];
            this.MapCases[0, 0, 0] = MapCase.Wall;
            this.MapCases[1, 0, 0] = MapCase.Blue;
            this.MapCases[0, 0, 1] = MapCase.Wall;
            this.MapCases[1, 0, 1] = MapCase.Blue;
            this.MapCases[0, 1, 0] = MapCase.Blue;
            this.MapCases[1, 1, 0] = MapCase.Empty;
            this.MapCases[0, 1, 1] = MapCase.Blue;
            this.MapCases[1, 1, 1] = MapCase.Empty;
        }

        public void Init(int x, int y, int z)
        {
            this.MapCases = new MapCase[x, y, z];
            // largeur
            for (int i = 0; i < x; i++)
            {
                // Hauteur
                for (int j = 0; j < y; j++)
                {
                    // profondeur
                    for (int k = 0; k < z; k++)
                    {
                        if (j > 1)
                        {
                            this.MapCases[i, j, k] = MapCase.Empty;
                            continue;
                        }
                        this.MapCases[i, j, k] = MapCase.Empty;
                        if (j == 0)
                        {
                            if ((i + k) % 3 == 0)
                                this.MapCases[i, j, k] = MapCase.Blue;
                            if ((i + k) % 3 == 1)
                                this.MapCases[i, j, k] = MapCase.Blue;
                            if ((i + k) % 3 == 2)
                                this.MapCases[i, j, k] = MapCase.Blue;
                        }
                    }
                }
            }
            for (int i = 0; i < x; i++)
            {
                for (int k = 0; k < z; k++)
                {
                    if (i == 0 || i == x - 1)
                    {
                        this.MapCases[i, 0, k] = MapCase.Wall;
                        this.MapCases[i, 1, k] = MapCase.Left;
                    }
                    if (k == 0 || k == z - 1)
                    {
                        this.MapCases[i, 0, k] = MapCase.Wall;
                        this.MapCases[i, 1, k] = MapCase.Up;
                    }
                    if (i % 4 == 0 && k % 4 == 0)
                    {
                        this.MapCases[i, 0, k] = MapCase.Wall;
                        this.MapCases[i, 1, k] = MapCase.Star;
                    }
                }
            }
        }
    }
}
